﻿Option Explicit On
Option Strict On

Module clsCommon

    Public Function fncShowErr(ByVal strMessage As String) As DialogResult

        Try
            Return MessageBox.Show(strMessage, clsConst.gcstrApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, clsConst.gcstrApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Function

    Public Function fncShowWarning(ByVal strMessage As String, Optional ByVal ctrlFocusTo As Control = Nothing) As DialogResult
        Try
            If ctrlFocusTo IsNot Nothing Then ctrlFocusTo.Focus()

            Return MessageBox.Show(strMessage, clsConst.gcstrApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning)

        Catch ex As Exception
            fncShowErr(ex.Message)
        End Try
    End Function

    Public Function fncShowConfirm(ByVal strMessage As String, Optional ByVal ctrlFocusTo As Control = Nothing) As DialogResult
        Try
            If ctrlFocusTo IsNot Nothing Then ctrlFocusTo.Focus()

            Return MessageBox.Show(strMessage, clsConst.gcstrApplicationName, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        Catch ex As Exception
            fncShowErr(ex.Message)
        End Try
    End Function

    Public Function fncIsBlank(ByVal str As String) As Boolean
        fncIsBlank = False

        Try
            'str = str.Trim()

            Return String.IsNullOrEmpty(str)

            Return True
        Catch ex As Exception
            fncShowErr(ex.Message)
        End Try
    End Function


    Public Function fncCnvString(ByVal objValue As Object) As String

        fncCnvString = ""

        Try
            If objValue Is Nothing Then Exit Function

            fncCnvString = CStr(objValue)
            fncCnvString = fncCnvString.Trim()

        Catch ex As Exception
            fncShowErr(ex.Message)
        End Try

    End Function


    Public Function fncCnvInt(ByVal objValue As Object) As Integer

        fncCnvInt = 0

        Try
            If objValue Is Nothing Then Exit Function

            If fncIsBlank(objValue.ToString()) Then Exit Function

            If IsNumeric(objValue) Then

                fncCnvInt = CInt(objValue)

            End If

            
        Catch ex As Exception
            fncShowErr(ex.Message)
        End Try

    End Function

End Module
